<#escape x as x?html> <@h.commonHead title="后台管理系统" keywords="开源,永久免费"
description="springrain开源系统管理后台"/>
<script src="${ctx}/js/custom/common/form.js"></script>
</head>
<body>
	<div class="layui-layout layui-layout-admin">
		<@h.naviHeader /> <@h.leftMenu />
		<!-- 主体内容开始 -->
		<div class="layui-body site-demo">
			<SCRIPT type="text/javascript">
    /* var orgTreesetting = {
        callback: {
            onClick: orgzTreeOnClick
        },
        data : {
            simpleData : {
                enable : true,
                idKey : "id",
                pIdKey : "pid",
                rootPId : "null"
            }
        }
    };
    
    
    
    
    var orgSelectSetting = {
            callback: {
                onClick: clickOrgValue
            },
            data : {
                simpleData : {
                    enable : true,
                    idKey : "id",
                    pIdKey : "pid",
                    rootPId : "null",
                }
            }
        };
        
    var selectOrgZtree;
    var orgjsondata4select;
    

    $(document).ready(function() {
        jQuery.post("${ctx}/system/org/list/json",
        function(_json) {
            if (_json.status == "success") {
                orgjsondata4select=_json;
                $.fn.zTree.init($("#orgListTree"), orgTreesetting,_json.data);
                var zTree =$.fn.zTree.getZTreeObj("orgListTree");
                 zTree.expandAll(true);
            } else {
                myalert(_json.message);
            }
        });
        
        //ajaxUserIdSelect2();
        
        //ajaxUserIdSelect2("${ctx}/system/user/ajax/select2","managerId",datafunction,selectfunction);
        
        select2ajax("#managerId","${ctx}/system/user/ajax/select2");
        
    });
    
    
    function orgzTreeOnClick(event, treeId, treeNode) {
        showdata(treeNode);
    };
    
    function clickOrgValue(event, treeId, treeNode) {
        jQuery("#pname").val(treeNode.name);
        jQuery("#pid").val(treeNode.id);
    };
    
    function showdata(result) {
        $("#btn_add").hide();
        $("#btn_update").show();
        $("#btn_delete").show();
        $("#btn_reload").show();
        for (var s in result) {
            set_val(s, result[s]);
        }
        var _pid=result["pid"];
        if((!_pid)||_pid==null||_pid=="null"||_pid==""){
            jQuery("#pid").val("");
        }else{
            jQuery("#pid").val(_pid);
        }
        var _pNode= result.getParentNode();
        if(_pNode){
            jQuery("#pname").val(_pNode["name"]);
        }else{
            jQuery("#pname").val("");
        }
        
        
        
        
        //回选 下拉框
        jQuery("#state option[value='"+result['state']+"']").prop("selected",true);
        //  设置 主管的下拉框
        if(result["managerId"]){
            jQuery("#managerId").empty();
            jQuery("#managerId").append("<option value='"+result["managerId"]+"'  selected>"+result["managerName"]+"</option>");
            jQuery("#managerId").trigger("change");
        }

        
        
        
    }
    
    
    function deleteOrg(){
        var id=jQuery("#id").val();
        if(!id||id==""){
            myalert("请选择你要删除的记录");
            return;
        }else{
            var _url="${ctx}/system/org/delete?id="+id;
            var listurl="${ctx}/system/org/list";
            mydelete(_url,listurl,{},"部门下的子部门也会被删除,确定要删除部门?");
        }
    }
    function showOrgTree(){
        
        
        if(!selectOrgZtree){
            $.fn.zTree.init($("#selectOrgTree"), orgSelectSetting,orgjsondata4select.data);
            
             selectOrgZtree =$.fn.zTree.getZTreeObj("selectOrgTree");
             selectOrgZtree.expandAll(true);
             selectZtreeOneNode(jQuery("#pid").val(),"selectOrgTree");
        }
        
        
        
        
        
        
        //页面层-自定义
        layer.open({
          shadeClose:true,
          closeBtn: 1,
          btn: ['确定'], //按钮
          type: 1,
          title: "选择父部门",
          skin: 'layui-layer-rim', //加上边框
          area: ['600px', '400px'], //宽高
          //shadeClose: true,
          content: $("#div_select_org_tree")
        });
        
    }
     */
    
    
    
</SCRIPT>
			<div class="operate panel panel-default" style="height: 65px;">
				<div class="panel-body">


					<div class="pull-right">
						<a id="btn_reload" onclick="location.reload();"
							class="btn btn-sm btn-primary" style="display: none;"> 跳转到新增
							>> </a>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<a id="btn_add"
							onclick="commonSaveForm('updateForm','${ctx}/system/org/list');"
							class="btn btn-sm btn-primary"><img
							src="${ctx}/images/btn_save.png" style="vertical-align: middle;" />保存新增</a>
						<a id="btn_update" style="display: none;"
							onclick="commonUpdateForm('updateForm','${ctx}/system/org/list');"
							class="btn btn-sm btn-primary"><img
							src="${ctx}/images/btn_save.png" style="vertical-align: middle;" />保存修改</a>
						<a id="btn_delete" style="display: none;" onclick="deleteOrg();"
							class="btn btn-sm  btn-danger">删除</a>
					</div>
				</div>
			</div>


			<!-- 功能操作区域结束 -->
			<!-- 列表显示区域  -->
			<div class="row">
				<div class="col-sm-4">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="widget-title">部门信息</h4>
						</div>
						<div class="widget-body">
							<div class="widget-main">
								<ul id="orgListTree" class="ztree"></ul>
							</div>
						</div>
					</div>
				</div>
				<div class="col-sm-8 sub_content">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="widget-title">详细信息</h4>
						</div>
						<div class="widget-body">
							<div class="widget-main">
								<form id="updateForm" name="updateForm" method="post"
									action="${ctx}/system/org/update"
									class="form-horizontal clearfix">
									<input type="hidden" name="id" id="id"> <input
										type="hidden" name="opmode" id="opmode" value="">

									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="name">名称*：</label>
										<div class="col-sm-8">
											<input class="form-control" datatype="*1-200"
												errormsg="部门名称长度1--200位之间!" nullmsg="名称不能为空" type="text"
												id="name" name="name"> <span
												class="Validform_checktip"></span>
										</div>
									</div>

									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="dept_name">上级部门*：</label>
										<div class="col-sm-8">
											<div class="input-group">
												<input name="pname" class="form-control" id="pname"
													type="text" readonly="readonly" /> <input name="pid"
													id="pid" type="hidden" />
												<div class="input-group-btn">
													<a href="javascript:showOrgTree();"
														class="btn btn-sm btn-primary"> <i
														class="fa fa-search"></i>
													</a>
												</div>
											</div>
										</div>
									</div>

									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="managerId">主管：</label>
										<div class="col-sm-8">
											<select id="managerId" name="managerId" class="form-control">

											</select>
										</div>
									</div>


									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="sortno">排序：</label>
										<div class="col-sm-8">
											<input class="form-control" type="text" id="sortno"
												name="sortno" datatype="n1-16" errormsg="请输入正确数值"
												nullmsg="排序不能为空!">
										</div>
									</div>

									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="state">是否可用：</label>
										<div class="col-sm-8">
											<select id="state" name="state" class="form-control">
												<option value="是">是</option>
												<option value="否">否</option>
											</select>
										</div>
									</div>


									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="description">描述：</label>
										<div class="col-sm-8">
											<textarea class="form-control" name="description"
												id="description" rows="5" class="col-xs-12"></textarea>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>

				</div>
			</div>


			<div id="div_select_org_tree">
				<ul id="selectOrgTree" class="ztree"></ul>
			</div>




		</div>
		<!-- 主体内容结束 -->
		<@h.footer />
	</div>
</body>
</html>
</#escape>
